<?
require_once("lang.php");

$start_time = microtime_float();

//ob_start("callback");

//Đếm số lượng người truy cập
$db_visited	= new db_execute("UPDATE visited SET vis_counter = vis_counter + 1");
unset($db_visited);

$db_detail = new db_query('SELECT sta_title,sta_description FROM statics_multi WHERE sta_id = ' . $con_static_contact . ' AND lang_id = ' . $lang_id . ' LIMIT 1');
$detail = mysql_fetch_array($db_detail->result);
unset($db_detail);

$gs_form = 'contact';
$gs_action = $_SERVER['REQUEST_URI'];
$gs_errorMsg = '';

$url = getURL('url', 'str', 'GET', '', 2);

//Lấy dữ liệu đề giữ nguyên trạng thái khi submit error
$ct_name			= getValue("ct_name", "str", "POST", "");
$ct_address			= getValue("ct_address", "str", "POST", "");
$ct_phone			= getValue("ct_phone", "str", "POST", "");
$ct_mobile			= getValue("ct_mobile", "str", "POST", "");
$ct_email			= getValue("ct_email", "str", "POST", "");
$ct_title			= getValue("ct_title", "str", "POST", "");
$ct_content			= getValue("ct_content", "str", "POST", "");
$ct_date			= time();
$url				= getValue('url', 'str', 'POST', $url);

// Get action and security code variable
$security_code	= getValue("security_code", "str", "POST", "");
$action			= getValue("action", "str", "POST", "");
if ($action == 'execute')
{
	/*
	Call class form:
	1). Ten truong
	2). Ten form
	3). Kieu du lieu , 0 : string , 1 : kieu int, 2 : kieu email, 3 : kieu double, 4 : kieu hash password
	4). Noi luu giu data  0 : post, 1 : variable
	5). Gia tri mac dinh, neu require thi phai lon hon hoac bang default
	6). Du lieu nay co can thiet hay khong
	7). Loi dua ra man hinh
	8). Chi co duy nhat trong database
	9). Loi dua ra man hinh neu co duplicate
	*/
	$myform = new generate_form();
	//Add table insert data
	$myform->addTable('contacts');
	$myform->add("ct_name", "ct_name", 0, 1, " ", 1, "Bạn chưa nhập họ và tên.", 0, "");
	$myform->add("ct_address", "ct_address", 0, 1, " ", 1, "Bạn chưa nhập địa chỉ.", 0, "");
	$myform->add("ct_phone", "ct_phone", 0, 1, " ", 0, "", 0, "");
	$myform->add("ct_mobile", "ct_mobile", 0, 1, " ", 1, "Bạn chưa nhập di động.", 0, "");
	$myform->add("ct_email", "ct_email", 0, 1, " ", 1, "Bạn chưa nhập email.", 0, "");
	$myform->add("ct_title", "ct_title", 0, 1, " ", 1, "Bạn chưa nhập tiêu đề.", 0, "");
	$myform->add("ct_content", "ct_content", 0, 1, " ", 0, "Bạn chưa nhập nội dung.", 0, "");
	$myform->add("ct_date", "ct_date", 1, 1, 0, 0, "", 0, "");
	
	// Check form data
	$gs_errorMsg .= $myform->checkdata();
	
	// Check security code
	if (check_session_security($security_code) == 0)
	{
		$gs_errorMsg .= '&bull; "' . tdt("Ma_so_an_toan") . '" ' . tdt("khong_phu_hop") . "<br />";
	}
	
	if ($gs_errorMsg == '')
	{
		//Insert to database
		$myform->removeHTML(0);
		$db_insert = new db_execute($myform->generate_insert_SQL());
		unset($db_insert);
		
		// Close window
		echo '<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">';
		echo '<script type="text/javascript">alert("' . tdt("Ban_da_gui_thanh_cong") . '");</script>';
		
		//Redirect after insert complate
		redirect($gs_redirect);
	}
}
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<meta name="keywords" content="<?=str_replace("\n", "", htmlspecialchars($con_meta_keywords))?>">
<meta name="description" content="<?=str_replace("\n", "", htmlspecialchars($con_meta_description))?>">
<title><?=$detail['sta_title']?> | <?=$con_site_title?></title>
<style type="text/css" media="all">@import "<?=$theme_csspath?>main.css";</style>
<style type="text/css" media="all">@import "<?=$theme_csspath?>thickbox.css";</style>
<style type="text/css" media="all">@import "<?=$theme_imagepath?>theme.css";</style>
</head>
<body<?=$body_style?>>
<div id="body">
	<div id="container_body">
		<div id="container_header"><? include($real_path . "includes/inc_header.php");?></div>
		<div id="container_content">
            <div id="container_content_left"><? include($real_path . "includes/inc_home_left.php");?></div>
            <div id="container_content_center">
            <?
			include($real_path . "includes/inc_module_center_search_form.php");
            include($real_path . "includes/inc_contact.php");
            ?>
            </div>
            <div id="container_content_right">
            <?
			include($real_path . "includes/inc_home_right.php");
			?>
            </div>
            <div class="clear"></div>
        </div>
		<div id="footer"><? include($real_path . "includes/inc_footer.php");?></div>
    </div>
</div>
</body>
</html>
<?
//ob_end_flush();
?>